local meta = FindMetaTable( "Player" )
if (!meta) then 
    Msg("ALERT! Could not hook Player Meta Table\n")
    return 
end

function meta:Class()
	return Class:Get( self:ClassId() )
end

function meta:ClassId()
	return self.PlyClass
end

function meta:SetClass( class )

	if type( class ) == "string" then
		class = Class:IdByName( class )
		
		if !class then
			return
		end
	end
	
	local Class = Class:Get( class )
	
	if !Class then
		return
	end
	
	if SERVER then //The NWVARS is taking care of this client-side
		self.PlyClass = class
	else
		chat.AddText(Color(255,255,255,255), "You are now a ", Color(0,255,0,255), Class:GetName() ,Color(255,255,255,255),"!")
	end 
	
	hook.Add("ClassChange", GAMEMODE, self )
	Class:NewPlayer( self )
	
end

hook.Add("PlayerSpawn", "ClassChooseCall", function( ply )

	local Class = ply:Class()
	
	if !Class then
		Msg("ATTETION! Player with invalid class " .. tostring( ply:ClassId() ) .. "\n")
	end
	
	Class:Spawn( ply )
	
end )

hook.Add("PlayerDeath", "ClassPlayerDeath", function( ply )

	local Class = ply:Class()
	
	if !Class then
		Msg("ATTETION! Player with invalid class " .. tostring( ply:ClassId() ) .. "\n")
	end
	
	Class:Death( ply )

end)